package com.all.play.mysvnbanchone;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.all.play.mysvnbanchone.viewdecoration.DividerGridItemDecorationCopy;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<String> mData;
    private RvAdapter adapter;
    //private MyNewItemDecration decration;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        initData();

    }

    boolean isGride = true;

    public void change(View v) {
//        if (decration!=null)
//        recyclerView.removeItemDecoration(decration);
        if (!isGride) {
            recyclerView.setLayoutManager(new GridLayoutManager(this,3));
            //recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
          //  recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
           // decration=new MyNewItemDecration(this,LinearLayoutManager.VERTICAL);
        } else {
//            recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
            recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
            //decration=new MyNewItemDecration(this,LinearLayoutManager.HORIZONTAL);

        }
        //recyclerView.addItemDecoration(decration);

        isGride = !isGride;


    }


    public void add(View view) {
        if (adapter != null) {

            adapter.addItem(0);


        }
    }

    public void delete(View view) {
        if (adapter != null) {

            adapter.remove(0);


        }
    }

    private void initData() {
        adapter = new RvAdapter(this, mData);
        //recyclerView.setLayoutManager(new LinearLayoutManager(this));
        //recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setLayoutManager(new GridLayoutManager(this,3));
        recyclerView.setAdapter(adapter);


        recyclerView.setItemAnimator(new DefaultItemAnimator());

        //recyclerView.addItemDecoration(new MyItemDecoration(this,LinearLayoutManager.VERTICAL));
//        GridItemDecoration decoration = new GridItemDecoration(this, LinearLayoutManager.VERTICAL);
//        recyclerView.addItemDecoration(decoration);
        //recyclerView.addItemDecoration(new MyNetItemDecration(10,this));
        //decration = new MyNewItemDecration(this, LinearLayoutManager.VERTICAL);

        //MyNewGridItemDecration decoration=new MyNewGridItemDecration(this);
        //MyOtherNewGridItemDecration decoration=new MyOtherNewGridItemDecration(this,adapter.getItemCount()-1);
        //GridItemDecoration decoration = new GridItemDecoration(this, GridLayoutManager.VERTICAL);
       // GridDivider decoration = new GridDivider(this,10,R.color.red);
        //MyGetDecoration decoration = new MyGetDecoration(0,this,5);
        //MyNetItemDecration decoration = new MyNetItemDecration(10,this);
       // MyNetItemDecration decoration = new MyNetItemDecration(0, this);
        DividerGridItemDecorationCopy decoration = new DividerGridItemDecorationCopy(this, 0, 0);
        recyclerView.addItemDecoration(decoration);
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.rv);
        mData = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
//            if (i % 2 == 0) {
//
//                mData.add("hashiqi" + i);
//            } else {
//
//                mData.add("这是中文的描述,和为了显示出瀑布流效果来添加一串文字" + i);
//            }

            mData.add("hashiqi" + i);
        }
    }
}
